/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace DaveSexton.DocProject
{
	internal sealed class ExternalSourceTypeConverter : TypeConverter
	{
		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ExternalSourceTypeConverter" /> class.
		/// </summary>
		public ExternalSourceTypeConverter()
		{
		}
		#endregion

		#region Methods
		public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
		{
			return destinationType == typeof(string);
		}

		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
		{
			ICollection<Source> sources = value as ICollection<Source>;

			if (value == null || destinationType != typeof(string))
				return base.ConvertTo(context, culture, value, destinationType);
			else
			{
				int directoryCount = 0, assemblyCount = 0, fileCount = 0;

				foreach (Source source in sources)
				{
					if (source.Input.IsDirectory)
						directoryCount++;
					else if (source.Input.IsAssembly)
						assemblyCount++;
					else
						fileCount++;
				}

				return string.Format(culture, Resources.Text.ExternalSourcesPropertyText, sources.Count, directoryCount, assemblyCount, fileCount);
			}
		}
		#endregion
	}
}
